﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace LibSystem
{
    public partial class Form3 : Form
    {
        private String serch;
        private ListViewItem itemx = new ListViewItem();
        private MySqlConnection myconn;
        public Form3(MySqlConnection conn,String x)
        {
            serch = x;
            myconn = conn;
            InitializeComponent();
        }
        

        private void Form3_Load(object sender, EventArgs e)
        {
            listView1.View = View.Details;
            listView1.GridLines = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String mystr = "select * from book where " + serch + " like '" + "%" + textBox1.Text + "%" + "'";
            MySqlCommand mycmd = new MySqlCommand(mystr, myconn);
            MySqlDataReader myreader = mycmd.ExecuteReader();
            listView1.Clear();
            //listView1.Update();
            listView1.Columns.Add("图书编号", 65, HorizontalAlignment.Left);
            listView1.Columns.Add("书名", 100, HorizontalAlignment.Left);
            listView1.Columns.Add("作者", 80, HorizontalAlignment.Left);
            listView1.Columns.Add("出版社", 120, HorizontalAlignment.Left);
            listView1.Columns.Add("出版时间", 150, HorizontalAlignment.Left);
            while (myreader.Read())
            {
                itemx = listView1.Items.Add(myreader[0].ToString(), 0);
                itemx.SubItems.Add(myreader[1].ToString());
                itemx.SubItems.Add(myreader[2].ToString());
                itemx.SubItems.Add(myreader[3].ToString());
                itemx.SubItems.Add(myreader[5].ToString());
            }
            
            myreader.Close();
        }
    }
}
